//
//  HealthDetailViewController.m
//  SmartWatch
//
//  Created by zwj on 2022/11/26.
//

@interface ProgressView : UIView
- (void)setColorArray:(NSArray *)colorArr lengthArray:(NSArray *)lengthArr;
@end

@implementation ProgressView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        ViewCorner(self, 6.0);
    }
    return self;
}

- (void)setColorArray:(NSArray *)colorArr lengthArray:(NSArray *)lengthArr {
    CGFloat leftWidth = 0.0;
    for (int i = 0; i < lengthArr.count; i++) {
        NSNumber *num = lengthArr[i];
        CGFloat width = self.width * [num floatValue] * 1.0;
        
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(leftWidth, 0, width, self.height)];
        view.backgroundColor = colorArr[i];
        [self addSubview:view];
        leftWidth += width;
    }
}

@end

#import "HealthDetailViewController.h"

@interface HealthDetailViewController ()

@end

@implementation HealthDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.isHideNavigationBar = YES;
    
    self.view.backgroundColor = BACKGROUNDCOLOR;
}

- (void)initSubviews {
    [super initSubviews];
    
    UIImageView *backImage = [[UIImageView alloc]initWithImage:UIImageMake(@"monitor_health_back")];
    backImage.frame = CGRectMake(0, 0, kScreenWidth, 220);
    [self.view addSubview:backImage];
    
    MyLinearLayout *navView = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Horz];
    navView.myHorzMargin = 0;
    navView.gravity = MyGravity_Vert_Center | MyGravity_Horz_Between;
    navView.myHeight = 44;
    navView.myTop = StatusBarHeight;
    navView.padding = UIEdgeInsetsMake(0, 15, 0, 15);
    [self.view addSubview:navView];
    
    {
        UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [backBtn setImage:UIImageMake(@"icon_arrow_left") forState:UIControlStateNormal];
        backBtn.mySize = CGSizeMake( 40, 40);
        backBtn.imageEdgeInsets = UIEdgeInsetsMake(10,10,10,10);
        [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        [navView addSubview:backBtn];
        
        UILabel *content = [UILabel createLabelText:@"指数解析" font:UIFontBoldMake(17) textColor:COLOR1515];
        content.mySize = kAutoSize;
        [navView addSubview:content];
        
        UIButton *right = [UIButton createButtonText :@"     " font:UIFontMake(14) textColor:COLOR1515];
        right.mySize = kAutoSize;
        [navView addSubview:right];
        
    }
    
    UIScrollView *scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, NavigationContentTop, kScreenWidth, kScreenHeight - NavigationContentTop)];
    scrollView.showsVerticalScrollIndicator = NO;
    [self.view addSubview:scrollView];
    
    MyLinearLayout *root = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
    root.myHorzMargin = 0;
    root.myTop = 15;
    root.padding = UIEdgeInsetsMake(0, 15, 0, 15);
    [scrollView addSubview:root];
    
    MyLinearLayout *top = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
    top.myHorzMargin = 0;
    top.myHeight = 215;
    top.padding = UIEdgeInsetsMake(29, 15, 15, 15);
    top.gravity = MyGravity_Horz_Center;
    ViewCorner(top, 15);
    [top az_setGradientBackgroundWithColors:@[[UIColor colorWithRGB:0xFFFFFF alpha:0.5],[UIColor colorWithRGB:0xFFFFFF alpha:0.9],[UIColor colorWithRGB:0xFFFFFF alpha:1.0]] locations:@[@0.0,@0.3,@1.0] startPoint:CGPointMake(0.5, 0) endPoint:CGPointMake(0.5, 1)];
    [root addSubview:top];
    
    {
        MyLinearLayout *backView = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
        backView.mySize = CGSizeMake(100, 100);
        ViewCorner(backView, 50);
        ViewBorder(backView, 2.0, HexColor(@"#ECF5F5"));
        backView.padding = UIEdgeInsetsMake(5, 5, 5, 5);
        backView.subviewVSpace = 5;
        backView.gravity = MyGravity_Horz_Center;
        [top addSubview:backView];
        
        
        {
            UIImageView *image = [[UIImageView alloc]initWithImage:UIImageMake(@"monitor_touxiang")];
            image.mySize = CGSizeMake(36, 36);
            [backView addSubview:image];
            
            UILabel *name = [UILabel createLabelText:@"内分泌指数" font:UIFontMake(12) textColor:COLOR666];
            name.mySize = kAutoSize;
            [backView addSubview:name];
            
            UILabel *numberLabel = [UILabel new];
            numberLabel.mySize = kAutoSize;
            numberLabel.text = @"72.0";
            NSString *leftNum = [numberLabel.text componentsSeparatedByString:@"."].firstObject;
            NSString *rightNtm = [numberLabel.text componentsSeparatedByString:@"."].lastObject;
            rightNtm = FormatString(@".%@",rightNtm);
            numberLabel.attributedText = AttributedString(leftNum, UIFontMake(20), THEME_COLOR, rightNtm, UIFontMake(12), THEME_COLOR, NSTextAlignmentLeft, 0);
            [backView addSubview:numberLabel];
        }
        
        ProgressView *progress = [[ProgressView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth - 100, 12)];
        progress.myTop = 30;
        progress.myHorzMargin = 20;
        progress.myHeight = 12;
        progress.backgroundColor = UIColorRed;
        [progress setColorArray:@[HexColor(@"#A40000"),HexColor(@"#FF3737"),HexColor(@"#F3BE00"),HexColor(@"#0FE4D2")] lengthArray:@[@0.2,@0.3,@0.1,@0.4]];
        [top addSubview:progress];
        
        MyLinearLayout *bottomLay = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Horz];
        bottomLay.myTop = 5;
        bottomLay.myHorzMargin = 20;
        bottomLay.gravity = MyGravity_Vert_Center | MyGravity_Horz_Between;
        bottomLay.myHeight = 20;
        [top addSubview:bottomLay];
        
        NSArray *array = @[@"不平衡",@"平衡"];
        for (int i = 0; i < array.count; i++) {
            UILabel *name = [UILabel createLabelText:array[i] font:UIFontMake(14) textColor:COLOR666];
            name.mySize = kAutoSize;
            [bottomLay addSubview:name];
        }
        
    }
    
    MyLinearLayout *bottom = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
    bottom.myTop = 15;
    bottom.myHorzMargin = 0;
    bottom.myHeight = kAutoHeight;
    bottom.padding = UIEdgeInsetsMake(15, 15, 15, 15);
    bottom.subviewVSpace = 15;
    ViewCorner(bottom, 15);
    bottom.backgroundColor = COLOR_4;
    [root addSubview:bottom];
    
    {
        UIView *line = [[UIView alloc]initWithFrame:CGRectMake(15, 28, 64, 6)];
        line.useFrame = YES;
        [line az_setGradientBackgroundWithColors:@[HexColor(@"#86F1E8"),HexColor(@"#ABE1FF")] locations:@[@0.0,@1.0] startPoint:CGPointMake(0.5, 0.0) endPoint:CGPointMake(0.5, 1.0)];;
        [bottom addSubview:line];
        
        
        UILabel *name = [UILabel createLabelText:@"指数解析" font:UIFontBoldMake(16) textColor:COLOR1515];
        name.mySize = kAutoSize;
        [bottom addSubview:name];
        
        UILabel *content = [UILabel createLabelText:@"内分泌指数来自于西医学观点，代表身体荷尔蒙平衡状态。"
                            "当内分泌指数大于60时，代表身体荷尔蒙运作平衡；"
                            "当内分泌指数小于60时，代表身体荷尔蒙运作不平衡；"
                            "不平衡可能原因有二个方向："
                            "1.肾上腺、甲状腺过度消耗（太过）"
                            "2.胰腺过度消耗（不足）" font:UIFontMake(14) textColor:HexColor(@"#454545")];
        content.myHorzMargin = 0;
        content.myHeight = kAutoHeight;
        [bottom addSubview:content];
        
        MyLinearLayout *back = [MyLinearLayout linearLayoutWithOrientation:MyOrientation_Vert];
        back.myHorzMargin = 0;
        back.padding = UIEdgeInsetsMake(10, 10, 10, 10);
        back.backgroundColor = HexColor(@"#FFF9F1");
        ViewCorner(back, 15);
        [bottom addSubview:back];
        
        {
            UILabel *tips = [UILabel createLabelText:@"*备注：当数值低于40时，表示内分泌腺体过度消耗，功能下降，等待修复；当数值低于10时，表示部分内分泌腺体功能丧失，进入极度失衡状态。" font:UIFontMake(13) textColor:HexColor(@"#AB6D53")];
            tips.myHorzMargin = 0;
            tips.myHeight = kAutoHeight;
            [back addSubview:tips];
        }
        
    }
    
                        
}



@end
